package progetto3.managerAB;

import sde.monitor.Condition;
import sde.monitor.Monitor;

public class ManagerH extends ManagerAB {
	
	private Monitor m = new Monitor();
	private Condition wait = m.newCondition();

	@Override
	public void request(MyRunnable r) {
		m.Enter();
		if (!canPass(r)) {
			w++;
			wait.Wait();
			w--;
		}
		entered(r);
		m.Exit();
	}

	@Override
	public void release(MyRunnable r) {
		m.Enter();
		exited(r);
		if((cnt[(r.getId()+1)%DIM]<2 || cntp==MAXP)&& w>0)
			wait.Signal();
		m.Exit();
	}
}
